const fs = require("fs"); // 读写文件

const {parse} = require("@babel/parser"); // 解析js

const types = require("@babel/types"); // 判断节点类型，生成新的节点

const traverse = require("@babel/traverse").default; // 遍历ast中的节点


const generator = require("@babel/generator").default; // 把AST代码转换成JS代码


let jscode = fs.readFileSync("./demo.js", {
    encoding: "utf-8",
}); // 读代码

let ast = parse(jscode); // 把代码转成Ast


let visitor = {
    //转换代码
}
traverse(ast, visitor);


let {code} = generator(ast, opts = {jsescOption: {"minimal": true}});
console.log(code);

fs.writeFile("decode.js", code, (error) => {
    console.log("写入成功")
});
